package com.hexiang.service.impl;


import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.hexiang.entity.User;
import com.hexiang.entity.UserAddedEvent;
import com.hexiang.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Resource
    private EventBus eventBus;
//    @Resource
//    private AsyncEventBus asyncEventBus;

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void save(User user) {
        log.info("saveUser,user:{}", user);
        eventBus.post(new UserAddedEvent(1, user));
    }
}